package com.example.yin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.yin.common.R;
import com.example.yin.mapper.BaseCategoryMapper;
import com.example.yin.model.domain.BaseCategory;
import com.example.yin.model.param.CategoryListParam;
import com.example.yin.model.param.CategorySaveParam;
import com.example.yin.service.BaseCategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseCategoryServiceImpl extends ServiceImpl<BaseCategoryMapper, BaseCategory> implements BaseCategoryService {

    @Override
    public R categoryList(CategoryListParam param) {
        List<BaseCategory> list = list(Wrappers.lambdaQuery(BaseCategory.class)
                .eq(BaseCategory::getParentId, param.getParentId())
                .eq(BaseCategory::getDelFlag, 0));
        return R.success(list);
    }

    @Override
    public Boolean saveCategory(CategorySaveParam param) {
        BaseCategory entity = new BaseCategory();
        BeanUtils.copyProperties(param, entity);
        return saveOrUpdate(entity);
    }
}
